package org.argeproje.resim.proc.math;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

import org.argeproje.resim.proc.ConnectionRule;
import org.argeproje.resim.proc.data.Data;
import org.argeproje.resim.proc.data.ExtremaDA;
import org.argeproje.resim.proc.data.ImageDA;


/*
Input : ImageDA
Output: 2-D double array of size 2 x number of image bands.
	    First row includes maximum value of each band.
	    Second row includes minimum value of each band.
 */
public class ExtremaPR extends MathPR {
	protected void setConnectionRules(ConnectionRule connRule){
		connRule.addInType(ImageDA.class, 0);
		connRule.addOutType(ExtremaDA.class);
	}
	public Data process() {
		PlanarImage im = getInputAsPlanarImage();
		ParameterBlock pb = new ParameterBlock();
		pb.addSource(im);
		pb.add(null);
		pb.add(1);
		pb.add(1);
		PlanarImage imout = JAI.create("extrema", pb);
		double[][] extrema = (double[][]) imout.getProperty("extrema");
		Data out = new ExtremaDA(extrema);
		setOutput(out);
		return getOutput();
	}

}
